package cn.org.timespace.easyframe.util.sms.telecom.receive;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cn.org.timespace.easyframe.util.sms.telecom.smgp.Client;
import cn.org.timespace.easyframe.util.sms.telecom.smgp.bean.Deliver;
import cn.org.timespace.easyframe.util.sms.telecom.smsUtil.SMGPDeliverMessage;

/**
 * ������Ϣ
 * */
public class ReceiveSms {

	/**
	 * ������Ϣ
	 */
	public static List<SMGPDeliverMessage> OnDeliver(Client client) {
		List<SMGPDeliverMessage> smgp = new ArrayList<SMGPDeliverMessage>();
		try {
			do {
				Deliver deliver = client.OnDeliver();
				SMGPDeliverMessage message = new SMGPDeliverMessage();
				if (deliver.IsReport == 1) {
					message.setDestTermID(deliver.DestTermID);
					message.setIsReport(deliver.IsReport);
					message.setLinkID(deliver.LinkID);
					message.setMsgContent(new String(deliver.MsgContent));
					message.setMsgFormat(deliver.MsgFormat);
					message.setMsgID(deliver.MsgID);
					message.setMsgLength(deliver.MsgLength);
					message.setRecvTime(deliver.RecvTime);
					message.setReportMsgID(deliver.ReportMsgID);
					message.setReserve(deliver.Reserve);
					message.setSrcTermID(deliver.SrcTermID);
					message.setTP_udhi(deliver.TP_udhi);
					
				} else {
					String encode = "ISO8859-1";
					if (deliver.MsgFormat == 8)
						encode = "iso-10646-ucs-2";
					if (deliver.MsgFormat == 15)
						encode = "GBK";
					
					message.setDestTermID(deliver.DestTermID);
					message.setIsReport(deliver.IsReport);
					message.setLinkID(deliver.LinkID);
					message.setMsgContent(new String(deliver.MsgContent, encode));
					message.setMsgFormat(deliver.MsgFormat);
					message.setMsgID(deliver.MsgID);
					message.setMsgLength(deliver.MsgLength);
					message.setRecvTime(deliver.RecvTime);
					message.setReportMsgID(deliver.ReportMsgID);
					message.setReserve(deliver.Reserve);
					message.setSrcTermID(deliver.SrcTermID);
					message.setTP_udhi(deliver.TP_udhi);
					
					
				}
				smgp.add(message);
			} while (true);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return smgp;

	}

}
